package com.hiwhitley.himei.module.me;

import android.content.Context;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Gravity;

import com.hiwhitley.himei.R;
import com.hiwhitley.himei.app.base.BaseFragment;

import butterknife.BindView;

/**
 * Created by hiwhitley on 2016/10/10.
 */

public class MeFragment extends BaseFragment {
    @BindView(R.id.toolbar)
    Toolbar mToolbar;
    @BindView(R.id.collapsing_toolbar)
    CollapsingToolbarLayout mCollapsingToolbar;
    @BindView(R.id.appbar)
    AppBarLayout mAppbar;
    @BindView(R.id.nested_scroll_view)
    NestedScrollView mNestedScrollView;
    private static final String TAG = "MeFragment";

    private ShowTabBottomListener mShowTabBottomListener;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        mShowTabBottomListener = (ShowTabBottomListener) context;
    }

    @Override
    protected int getContentViewId() {
        return R.layout.fragment_me;
    }

    @Override
    protected void init() {

    }

    @Override
    protected void setListener() {

        mCollapsingToolbar.setCollapsedTitleGravity(Gravity.CENTER_HORIZONTAL);
        mCollapsingToolbar.setExpandedTitleGravity(Gravity.CENTER_HORIZONTAL);
        mCollapsingToolbar.setTitle("关于");
        mNestedScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
            @Override
            public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
                int dy = scrollY - oldScrollY;
                Log.i(TAG, "onScrollChange" + dy);
                if (Math.abs(dy) > 5) {
                    if (dy > 0) {
                        mShowTabBottomListener.toggleTabBottom(false);
                    } else {
                        mShowTabBottomListener.toggleTabBottom(true);
                    }
                }
            }
        });
    }

    public interface ShowTabBottomListener {
        void toggleTabBottom(boolean isShow);
    }

}
